package com.jinzhi.jzweb.controller.infoCollect;

import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.common.utils.ApiResult;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzweb.domain.infoCollect.ActivityInfoCollectEntity;
import com.jinzhi.jzweb.service.infoCollect.ActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/jzweb/info")
@Api(value = "采集信息管理", tags = {"采集信息管理"})
public class ActivityController extends BaseController {
    @Resource
    private ActivityService activityService;

    @GetMapping()
    @RequiresPermissions("jzweb:infocollect:infocollect")
    String ProductType(){
        return "/eventresource/educationCode/educationCode";
    }


    @ResponseBody
    @GetMapping("/list")
    @RequiresPermissions("jzweb:infocollect:infocollect")
    @ApiOperation(value = "分页查询", notes = "分页查询")
    public Result<?> list(Integer pageNumber, Integer pageSize) {
        Page<ActivityInfoCollectEntity> page = activityService.getPage(pageNumber, pageSize);
        return Result.ok(page);
    }

    @ResponseBody
    @PostMapping("/collect")
    @RequiresPermissions("jzweb:infocollect:add")
    public ApiResult<?> collectInfo(@RequestBody ActivityInfoCollectEntity activityInfoCollectEntity) {
        ApiResult<Object> result;
        try {
            result = ApiResult.success(activityService.addActivityInfo(activityInfoCollectEntity));
        } catch (Exception e) {
            result = ApiResult.fail("提交失败，请重试后联系工作人员！");
        }
        return result;
    }

    @ResponseBody
    @PostMapping("/update")
    @RequiresPermissions("jzweb:infocollect:edit")
    public ApiResult<?> update(@RequestBody ActivityInfoCollectEntity activityInfoCollectEntity) {
        ApiResult<Object> result;
        try {
            result = ApiResult.success(activityService.updateInfo(activityInfoCollectEntity));
        } catch (Exception e) {
            result = ApiResult.fail("提交失败，请重试后联系管理员！");
        }
        return result;
    }

    @ResponseBody
    @GetMapping("/delete")
    @RequiresPermissions("jzweb:infocollect:remove")
    public ApiResult<?> delete(String id) {
        ApiResult<Object> result;
        try {
            result = ApiResult.success(activityService.deleteInfoById(id));
        } catch (Exception e) {
            result = ApiResult.fail("提交失败，请重试后联系工作人员！");
        }
        return result;
    }

    @ResponseBody
    @GetMapping("/export")
    @RequiresPermissions("jzweb:infocollect:export")
    public void export(HttpServletResponse response) {
        activityService.exportInfo(response);
    }


    @GetMapping("/info")
//    @RequiresPermissions("jzweb:infocollect:infocollect")
    String Info() {
        System.out.println("-------------- 进入跳转页面方法 ------------------");
        return "/eventresource/educationCode/educationCode";
    }

    @GetMapping("/add")
    @RequiresPermissions("jzweb:infocollect:add")
    String add() {
        return "/eventresource/educationCode/add";
    }

    @GetMapping("/edit/{id}")
    @RequiresPermissions("jzweb:infocollect:edit")
    String edit(@PathVariable("id") String id, Model model) {
        ActivityInfoCollectEntity activityInfoCollectEntity = activityService.selectById(id);
        model.addAttribute("ActivityInfoCollectEntity", activityInfoCollectEntity);
        return "/eventresource/educationCode/edit";
    }

//    @GetMapping("/detail/{id}")
//    String info(@PathVariable("id") String id, Model model) {
//        ActivityInfoCollectEntity activityInfoCollectEntity = activityService.selectById(id);
//        model.addAttribute("ActivityInfoCollectEntity", activityInfoCollectEntity);
//        return "/jzweb/educationCode/educationCode";
//    }
}
